package com.wswy.wyjk.ui.common

import android.os.Bundle
import com.raft.framework.base.RFBaseActivity
import com.wswy.wyjk.R
import com.wswy.wyjk.ui.EXTRA_DATA
import com.wswy.wyjk.ui.main.choose.ChooseCityFragment
import com.wswy.wyjk.ui.practice.ChapterListFragment
import com.wswy.wyjk.ui.practice.exam.ExamRecordFragment
import com.wswy.wyjk.ui.practice.exam.ExamResultFragment
import kotlinx.android.synthetic.main.layout_app_title.*

class CommonActivity : RFBaseActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_common)

        img_back.setOnClickListener {
            finish()
        }

        intent?.getStringExtra("path")?.let {
            showFragment(it)
        }?:kotlin.run {
            finish()
            return
        }

    }

    private fun showFragment(path:String){

        when(path){
            Router.CHAPTER_LIST -> {
                ChapterListFragment.newInstance()
            }
            Router.CHOOSE_CITY -> {
                ChooseCityFragment.newInstance()
            }
            Router.EXAM_RESULT -> {
                ExamResultFragment.newInstance()
            }
            Router.EXAM_RECORD -> {
                ExamRecordFragment.newInstance()
            }
            else -> null
        }?.let {

            it.arguments = intent?.getBundleExtra(EXTRA_DATA)

            tv_title.text = it.getPageTitle()

            supportFragmentManager.beginTransaction().replace(R.id.fl_container,it).commitNowAllowingStateLoss()

        }

    }


}